﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DataMonitor_Tools.Tools
{
    public static class DateTimeOperator
    {
        /// <summary>
        /// 获取2个日期间的日期字符串数组，格式为"MM-dd"
        /// </summary>
        /// <param name="date1"></param>
        /// <param name="date2"></param>
        /// <returns></returns>
        public static string[] GetDateStringsBetweenDates(DateTime date1, DateTime date2)
        {

            if (date1.Date == date2.Date)
            {
                return new string[0]; // 返回空数组
            }

            int days = Math.Abs((int)(date1 - date2).TotalDays);
            string[] dateStrings = new string[days];

            for (int i = 0; i < days; i++)
            {
                DateTime date = date1 < date2 ? date1.AddDays(i) : date2.AddDays(i);
                dateStrings[i] = date.ToString("MM-dd");
            }

            return dateStrings;
        }
    }
}
